package com.lee.xxlspringbatchdemo.job;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author ：liylw
 * @date ：Created in 2021/4/28 16:04
 */
@Component
@Slf4j
public class SampleJob {

    @XxlJob(value = "jobHandler",init = "init",destroy = "destroy")
    public void jobHandler(){
        Date now = new Date();
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        log.info("jobHandler:{},分片参数：当前分片序号 = {}, 总分片数 = {}",now,shardIndex,shardTotal);
        XxlJobHelper.log("Server Log jobHandler:{}",now);
    }

    public void init(){
        log.info("-------------init----------------");
    }
    public void destroy(){
        log.info("-------------destroy----------------");
    }

}
